package com.javaGather.demo;

public class Node<E> {
    private E v;
    private Node<?> next;


    public static void main(String[] args) {

        /**
         * 单链表
         */
        Node<String> node1 = new Node<>();
        node1.v = "a";
        Node<String> node2 = new Node<>();
        node2.v = "b";
        Node<String> node3 = new Node<>();
        node3.v = "c";

        node1.next = node2;
        node2.next = node3;
        node3.next = null;
        System.out.println("--------遍历--------");
        showNode(node1);
        System.out.println("-------------------");

        //新增节点
        Node<String> node4 = new Node<>();
        node4.v = "d";
        addNode(node3,node4);
        System.out.println("--------添加---------");
        showNode(node1);
        System.out.println("--------------------");

        //删除node2
        System.out.println("--------删除----- ---");
        node1.next = node3;
        showNode(node1);
        System.out.println("--------------------");

    }

    public static void showNode(Node<?> node) {
        //当前node节点
        while (node != null) {
            System.out.println(node.v);
            node = node.next;
        }
    }

    public static void addNode(Node<?> tailNode,Node<?> newNode){
        /**
         * 最后一个节点新增
         */
        tailNode.next = newNode;

    }

}
